
#
# Makefile
# WARNING: relies on invocation setting current working directory to Makefile location
# This is done in .vscode/task.json
#
MAKEFLAGS 			:= -j1 #$(shell nproc)
SRC_EXT      		:= c
OBJ_EXT				:= o
CC 					:= gcc

SRC_DIR				:= ./
WORKING_DIR			:= ./build
BUILD_DIR			:= $(WORKING_DIR)/obj
BIN_DIR				:= $(WORKING_DIR)/bin
UI_DIR 				:= ui

BIN 				:= $(BIN_DIR)/mkfatimg

WARNINGS 			:= 

CFLAGS 				:= -O0 -g $(WARNINGS)

DEFINES				:= -D SIMULATOR=1 -D LV_BUILD_TEST=0

LDFLAGS 			:= -lm -lpthread 


# project source and include files

INC := -I .
SRCS := ./main.c

INC += -I ./fatfs
SRCS += $(wildcard ./fatfs/*.c)


# project build

COMPILE				= $(CC) $(CFLAGS) $(INC) $(DEFINES)

OBJECTS    			:= $(patsubst $(SRC_DIR)%,$(BUILD_DIR)/%,$(SRCS:.$(SRC_EXT)=.$(OBJ_EXT)))

all: default

$(BUILD_DIR)/%.$(OBJ_EXT): $(SRC_DIR)/%.$(SRC_EXT) Makefile
	@echo 'Building project file: $<'
	@mkdir -p $(dir $@)
	@$(COMPILE) -c -o "$@" "$<"

default: $(OBJECTS)
	@mkdir -p $(BIN_DIR)
	@$(CC) -o $(BIN) $(OBJECTS) $(LDFLAGS)
	@echo '--------------'
	@echo 'build finsh: $(BIN)'

clean:
	rm -rf $(WORKING_DIR)

flash:
	$(BIN)



